﻿/**
 * Contains all the LevelData's, maintains and inits any
 * @author Bence Dobos
 */

package flapo;

import flapo.LevelData;
import flash.display.Sprite;
import gamelib2d.TileSet;
import gamelib2d.Layer;
import gamelib2d.MapData;
import flash.geom.ColorTransform;

class LevelContainer 
{

	public var LevelDatas: Array<LevelData>;
	public var maxLevel: Int;
	
	public function new() 
	{
		maxLevel = 8;
		var l: Int;
		LevelDatas = new Array<LevelData>();
		l = 0;
		var ld: LevelData;
		ld = new LevelData();
		ld.AddTile(new BackgroundInfo());
		ld.AddMap(new BackgroundMap1Info());
		LevelDatas.push(ld);

	}
	
	/*returns LevelData*/
	public function getLevel(levelnum: Int, screen: Sprite, scalefactor: Float, scaleoffset: Float) : Level
	{
		/*if (levelnum<0 || levelnum>maxLevel)
			return null;*/
		var retval: Level = null;
		var tiles: TileSet;
//		var layer: Layer;
		var numlayer: Int;
		var scale: Float;
		numlayer = 0;
		switch (levelnum)
		{
			case -2: //win
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new BlocksloseInfo(),
					8/10, 8/10, true, 0.2, 1.0, 1.0)); 			
			case -1: //win, lose
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new BlockswinInfo(),
					8/10, 8/10, true, 0.2, 1.0, 1.0)); 
				//tiles = new TileSet (screen);
				//tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new BlocksloseInfo(),
					8/10, 8/10, true, 0.2, 1.0, 1.0)); 	
			case 0:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1IntroInfo(), 0.5, 0.5, false));

				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back2Info(),
					0.5, 0.5, true, 0.6, 0.4));
				/*	
				++numlayer;		
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 1.0, 0.3));*/
				
				++numlayer;		
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new BlocksintroInfo(),
					8/10, 8/10, true, scale, 1.0, scale)); 

				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new NewInfo ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new NewIntroInfo(),
					1.0, 1.0, true, scale, 1.0, scale));
			case 1:
				retval = new Level(screen);
/*				tiles = new TileSet (screen);
				tiles.init (new BackgroundInfo ());  // BackgroundInfo.hx is generated by Tile Studio
				retval.addMyLayer(addNewLayer(screen, tiles, new BackgroundMap1Info(), 0.5, 0.5, false)); */
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1m2Info(), 0.5, 0.5, false)); 
				
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 1.0, 0.6));
					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm1l2Info(),
					8/10, 8/10, true, scale, 1.0, scale)); 
				++numlayer;
				//++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm1l1Info(),
					1.0, 1.0, true, scale, 1.0, scale)); 
			case 2:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1m4Info(), 0.5, 0.5, false)); 
				
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 1.0, 0.6));
					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm2l2Info(),
					8/10, 8/10, true, scale, 1.0, scale)); 
				++numlayer;
				//++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm2l1Info(),
					1.0, 1.0, true, scale, 1.0, scale)); 
				++numlayer;
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 2.0, 0.6));
			case 3:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1m3Info(), 0.5, 0.5, false)); 
					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm3l3Info(),
					8/10, 8/10, true, scale, 1.0, scale)); 
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm3l2Info(),
					1.0, 1.0, true, scale, 1.0, scale));
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm3l1Info(),
					1.0, 1.0, true, scale, 1.0, scale)); 
				++numlayer;
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 2.0, 0.6));
			case 7:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1NapInfo(), 0.5, 0.5, false)); 
					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm4l2Info(),
					8/10, 8/10, true, scale, 1.0, scale)); 
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm4l1Info(),
					1.0, 1.0, true, scale, 1.0, scale));
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 2.0, 0.6));
				++numlayer;		
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back2Info(),
					0.5, 0.5, true, 2.0, 0.6));
			case 5:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1m5Info(), 0.5, 0.5, false)); 
					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm6l2Info(),
					8/10, 8/10, true, scale, 1.0, scale)); 
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm6l1Info(),
					1.0, 1.0, true, scale, 1.0, scale));
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 1.0, 0.5));
				++numlayer;		
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back2Info(),
					0.5, 0.5, true, 2.0, 0.2));
			case 6:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1m6Info(), 0.5, 0.5, false)); 
					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm7l2Info(),
					8 / 10, 8 / 10, true, scale, 1.0, scale));
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 1.0, 0.5));
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back2Info(),
					0.5, 0.5, true, 2.0, 0.2));
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm7l1Info(),
					1.0, 1.0, true, scale, 1.0, scale));
			case 4:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1m1Info(), 0.5, 0.5, false)); 
				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back1Info(),
					0.5, 0.5, true, 1.0, 0.2));					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm8l1Info(),
					8 / 10, 8 / 10, true, scale, 1.0, scale));

				++numlayer;		
				tiles = new TileSet (screen);
				tiles.init (new Clouds1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Clouds1back2Info(),
					0.5, 0.5, true, 2.0, 0.2));
			case 8:
				retval = new Level(screen);
				tiles = new TileSet (screen);
				tiles.init (new Abstract1Info ());
				retval.addMyLayer(addNewLayer(true, screen, tiles, new Abstract1NapInfo(), 0.5, 0.5, false)); 
					
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				tiles = new TileSet (screen);
				tiles.init (new BlocksInfo ());
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm5l5Info(),
					8/10, 8/10, true, scale, 1.0, scale)); 
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm5l4Info(),
					1.0, 1.0, true, scale, 1.0, scale));
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm5l3Info(),
					1.0, 1.0, true, scale, 1.0, scale));
				++numlayer;
				scale = scalefactor * numlayer + scaleoffset;
				retval.addMyLayer(addNewLayer(false, screen, tiles, new Blocksm5l1Info(),
					1.0, 1.0, true, scale, 1.0, scale));
			default:
				retval = null;
		}
		return retval;
		//return LevelDatas[levelnum];
	}
	
	public function addNewLayer(isBackground, screen: Sprite, tiles: TileSet, data: MapData,
		?xscroll: Float = 1.0, ?yscroll: Float = 1.0,
		?transparent: Bool = true, ?scale: Float = 1.0,
		?alpha: Float = 1.0, ?gamma: Float = 1.0) : MyLayer
	{
		var layer: Layer;
		layer = new Layer (screen);
		layer.init (tiles, data, transparent, scale, scale, mrp_tile, mrp_tile, true, true );
		var colortransform : ColorTransform;
		colortransform = new ColorTransform(gamma, gamma, gamma, alpha, 0, 0, 0, 0);
		layer.setColorTransform(colortransform);
		var mylayer: MyLayer = new MyLayer(layer, xscroll, yscroll, colortransform);
		mylayer.isBackground = isBackground;
		var playerlayer: Sprite;
		playerlayer = new Sprite();
		mylayer.playerlayer = playerlayer;
		screen.addChild(playerlayer);
		return mylayer;
	}
	
}